package com.ssyc.student.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.makeramen.roundedimageview.RoundedImageView;
import com.ssyc.common.glide.ImageUtil;
import com.ssyc.common.manager.AccountUtils;
import com.ssyc.student.R;
import com.ssyc.student.activity.StudentVisitFriendActivity;
import com.ssyc.student.bean.FriendInfo;

import java.util.List;


/**
 * 学生端--好友列表适配器
 * Created by Administrator on 2018/5/3 0003.
 */

public class StFriendAdapter extends BaseQuickAdapter<FriendInfo.DataBean, BaseViewHolder> {

    private Context context;

    public StFriendAdapter(Context context, int layoutResId, @Nullable List<FriendInfo.DataBean> data) {
        super(layoutResId, data);
        this.context = context;
    }

    @Override
    protected void convert(BaseViewHolder helper, FriendInfo.DataBean item) {
        int pos = helper.getLayoutPosition();
        //皇冠
        ImageView lvKing = helper.getView(R.id.iv_king);

        //排名的TextView
        TextView tvPos = helper.getView(R.id.tv_pos);
        tvPos.setText((pos + 1) + "");
        if (pos == 0) {
            lvKing.setVisibility(View.VISIBLE);
            lvKing.setImageResource(R.drawable.st_king_one);
            tvPos.setBackgroundResource(R.drawable.st_first_pos_bg);
        } else if (pos == 1) {
            lvKing.setVisibility(View.VISIBLE);
            lvKing.setImageResource(R.drawable.st_king_two);
            tvPos.setBackgroundResource(R.drawable.st_second_pos_bg);
        } else if (pos == 2) {
            lvKing.setVisibility(View.VISIBLE);
            lvKing.setImageResource(R.drawable.st_king_three);
            tvPos.setBackgroundResource(R.drawable.st_third_pos_bg);
        } else {
            lvKing.setVisibility(View.INVISIBLE);
            tvPos.setBackgroundResource(R.drawable.st_four_pos_bg);
        }

        //头像
        RoundedImageView lvHead = helper.getView(R.id.iv_head);
        ImageUtil.displayImage(context, lvHead, item.getHeadimg());

        //等级
        TextView tvLerver = helper.getView(R.id.tv_lerver);
        tvLerver.setText("Lv." + item.getLevel());

        //姓名
        TextView tvName = helper.getView(R.id.tv_name);
        tvName.setText(item.getName() + "");

        //金币数
        TextView tvGold = helper.getView(R.id.tv_gold);
        tvGold.setText(item.getCoin() + "");

        //拜访按钮
        Button btPay = helper.getView(R.id.bt_pay);

        if(item.getUserId().equals(AccountUtils.getAccount(context))){
            btPay.setVisibility(View.INVISIBLE);
        }


        btPay.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //拜访
                Intent intent = new Intent(context,StudentVisitFriendActivity.class);
                intent.putExtra("userid",item.getUserId());
                intent.putExtra("toname",item.getName());
                context.startActivity(intent);
            }
        });
    }
}
